package com.example.commonlib.commonutil;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;

/**
 * Created by aiyou on 2017/8/22.
 */

public class PaletteUtil{

//    private static ImageView imageView;
//    private static RelativeLayout bgImageLayout;
//    private static Bitmap bitmap;
//    public static void setPaletteBgColor(Bitmap bitmaps,ImageView imageViews,RelativeLayout bgImageLayouts){
//        bitmap = bitmaps;
//        Palette.from(bitmap).generate(listener);
//        imageView = imageViews;
//        bgImageLayout = bgImageLayouts;
//    }
//
//
//    private static Palette.PaletteAsyncListener listener = new Palette.PaletteAsyncListener() {
//        @Override
//        public void onGenerated(Palette palette) {
//            if (palette != null){
//                Palette.Swatch vibrant = palette.getVibrantSwatch();//有活力的
//                Palette.Swatch vibrantDark = palette.getDarkVibrantSwatch();//有活力的，暗色
//                Palette.Swatch vibrantLight = palette.getLightVibrantSwatch();//有活力的，亮色
//                Palette.Swatch muted = palette.getMutedSwatch();//柔和的
//                Palette.Swatch mutedDark = palette.getDarkMutedSwatch();//柔和的，暗色
//                Palette.Swatch mutedLight = palette.getLightMutedSwatch();//柔和的,亮色
//                int vibrantRgb = 0;
//                int mutedLightRgb = 0;
//
//                if(vibrant != null){
//                    vibrantRgb = vibrant.getRgb();
//                }
//
//                if(mutedLight != null){
//                    mutedLightRgb = mutedLight.getRgb();
//                }
//
//                if(imageView != null){
//                    bgImageLayout.setBackgroundDrawable(changedImageViewShape(vibrantRgb,mutedLightRgb));
//                    showImageBg(imageView);
//                    imageView.setImageBitmap(bitmap);
//                }
//            }
//        }
//    };


    private static Drawable changedImageViewShape(int RGBValues, int two){
        GradientDrawable shape = new GradientDrawable(GradientDrawable.Orientation.TL_BR
                ,new int[]{RGBValues,two});
        shape.setShape(GradientDrawable.RECTANGLE);
        //设置渐变方式
        shape.setGradientType(GradientDrawable.LINEAR_GRADIENT);
        //圆角
        shape.setCornerRadius(8);
        return shape;
    }


    /**
     * 背景图片的讹渐显效果
     */
    static AlphaAnimation mShowAnimation = null;
    public static void showImageBg(ImageView imageView){
        if(null != mShowAnimation){

            mShowAnimation.cancel( );

        }

        mShowAnimation = new AlphaAnimation(0.0f, 1.0f);
        mShowAnimation.setDuration(1000);
        mShowAnimation.setFillAfter(true);
        imageView.startAnimation(mShowAnimation);
    }
}
